package com.framework.seedkit.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

import com.framework.seedkit.base.BaseApplication;

public class OSUtil {
	public static int widthPixels; 
	public static int heightPixels;
	public static float density;

	public static String BRAND;
	public static String MODEL; 
	public static int SDK; 
	
	public static String pkg;
	public static String verName;
	public static int verCode;


	public static void initSystemInfo() {
		BaseApplication context = BaseApplication.getInstance();
		WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		// 具体返回对象是WindowMangerIml类
		Display display = wm.getDefaultDisplay();
		DisplayMetrics displaysMetrics = new DisplayMetrics();
		display.getMetrics(displaysMetrics); 
		widthPixels = displaysMetrics.widthPixels;
		heightPixels = displaysMetrics.heightPixels;
		density = displaysMetrics.density;

		BRAND = Build.BRAND;
		MODEL = Build.MODEL;
		SDK = Build.VERSION.SDK_INT;
		
		pkg = context.getPackageName();
		try {
			PackageInfo info = context.getPackageManager().getPackageInfo(pkg, PackageManager.GET_SIGNATURES);
			verName = info.versionName;
			verCode = info.versionCode;
		} catch (PackageManager.NameNotFoundException e) {
			e.printStackTrace();
		}
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("\nwidthPixels = " + widthPixels);
		sb.append("\nheightPixels = " + heightPixels);
		sb.append("\ndensity = " + density);
		sb.append("\nwidthDp = " + widthPixels/density);
		sb.append("\nheightDp = " + heightPixels/density);
		sb.append("\nBRAND = " + BRAND);
		sb.append("\nMODEL = " + MODEL);
		sb.append("\nSDK = " + SDK);
		sb.append("\npkg = " + pkg);
		sb.append("\nverName = " + verName);
		sb.append("\nverCode = " + verCode);
		return sb.toString();
	}
	
	
}
